package com.example.myapplication;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

/*
数据库users.db，数据库表user
 */
public class DBOpenHelper extends SQLiteOpenHelper {

public  static final  String book="create table book(userId integer primary key autoincrement,name varchar(40),author varchar(40),number integer)";

private Context mcontext;
    public DBOpenHelper(@Nullable Context context) {
        super(context, "books.db", null, 1);
       this.mcontext=context;
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(book);
        db.execSQL("insert into book(name,author,number) values('三国演义','罗贯中',99)");
        db.execSQL("insert into book(name,author,number) values(?,?,?)", new String[]{"西游记", "吴承恩","11"});
        db.execSQL("insert into book(name,author,number) values(?,?,?)", new String[]{"水浒传", "施耐庵","22"});
        db.execSQL("insert into book(name,author,number) values(?,?,?)", new String[]{"红楼梦", "曹雪芹","33"});


    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {


    }
}
